package com.merlin.security.core.validate.code;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.merlin.security.core.properties.SecurityProperties;

/**
 * 验证码Bean配置
 * 目的：将接口后的实现做成可配置
 * @author merlin
 *
 */
@Configuration
public class ValidateCodeBeanConfig {
	
	@Autowired
	private SecurityProperties securityProperties;
	
	
	@Bean
	//系统在启动的时候，初始化之前，会先去找是否有imageCodeGenerator这个bean，如果有这个bean，就不会用这个bean，而是用找到的那个bean
	@ConditionalOnBean(name = "imageCodeGenerator")
	public ValidateCodeGenerator imageCodeGenerator() {
		ImageCodeGenerator codeGenerator = new ImageCodeGenerator();
		codeGenerator.setSecurityProperties(securityProperties);
		return codeGenerator;
	}

}
